package com.sky.mapper;

import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    void insert(Orders orders);

    List<OrderVO> getOrders(Long currentId, String status);

    @Select("select * from orders where id = #{id}")
    OrderVO selectById(String id);


    @Update("update orders set status = '7' where id = #{id}")
    void updatestatus(String id);


    @Select("select * from orders where status = #{orderNumber} and order_time < #{check_out_time}")
    List<Orders> selectByOrderPayTimeOut(int orderNumber, LocalDateTime check_out_time);


    @Select("select sum(amount) from orders where status = #{status} and order_time >#{begin} and order_time < #{end}")
    Double getSumAmount(Map map);

    int getSumUser(Map map);

    int getReportOrders(Map map);

    @Select("select count(*) from orders where order_time >#{begin} and order_time < #{end}")
    int gettotalOrderCount(LocalDateTime begin,LocalDateTime end);//订单总数

    @Select("select count(*) from orders where order_time >#{begin} and order_time < #{end} and status = #{status}")
    int getvalidOrderCount(LocalDateTime begin,LocalDateTime end,int status);//有效订单数

    @Select("select id from orders where order_time >#{begins} and order_time < #{ends} and status = #{status}")
    List<Long> getOrderIdList(LocalDateTime begins, LocalDateTime ends, int status);
    

    List<String> getTop10(List<Long> orderIdList);

    List<Long> getTop10Number(List<Long> orderIdList);
}
